﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _210624
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string password = TextBox2.Text;

            string constr = " Data Source = LAPTOP-ARH8HO5A  ; Initial Catalog = Student_db ; Integrate Security = True";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            string sql = "select * from StudentInfo where stu_name=@name and password=@pwd";

            SqlParameter[] pars =
            {
                new SqlParameter("@name",name),
                new SqlParameter("@pwd",password)
            };

            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.Parameters.AddRange(pars);

            SqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.Read())//能够读取下一条，就说明登录成功！
            {
                Session["CurrentUserName"] = name;
                Response.Redirect("WebForm3.aspx");
                Literal1.Text = "登录成功！";
            }
            else
            {
                Literal1.Text = "用户名或密码错误！";


            }
        }
    }
}